using System.Windows;
using System.Windows.Input;

namespace Supremacy.Client.Controls
{
    public class GameButton : GameButtonBase
    {
        #region Fields
        private object _defaultCommandParameter;
        #endregion

        #region Style Keys

        #region NormalTemplateKey Resource Key
        private static ComponentResourceKey _normalTemplateKey;

        public static ResourceKey NormalTemplateKey
        {
            get
            {
                if (_normalTemplateKey == null)
                {
                    _normalTemplateKey = new ComponentResourceKey(
                        typeof(GameButton),
                        "NormalTemplateKey");
                }
                return _normalTemplateKey;
            }
        }
        #endregion

        #region MinimalTemplateKey Resource Key
        private static ComponentResourceKey _minimalTemplateKey;

        public static ResourceKey MinimalTemplateKey
        {
            get
            {
                if (_minimalTemplateKey == null)
                {
                    _minimalTemplateKey = new ComponentResourceKey(
                        typeof(GameButton),
                        "MinimalTemplateKey");
                }
                return _minimalTemplateKey;
            }
        }
        #endregion

        #region GroupedVerticallyTemplateKey Resource Key
        private static ComponentResourceKey _groupedVerticallyTemplateKey;

        public static ResourceKey GroupedVerticallyTemplateKey
        {
            get
            {
                if (_groupedVerticallyTemplateKey == null)
                {
                    _groupedVerticallyTemplateKey = new ComponentResourceKey(
                        typeof(GameButton),
                        "GroupedVerticallyTemplateKey");
                }
                return _groupedVerticallyTemplateKey;
            }
        }
        #endregion

        #region GroupedHorizontallyTemplateKey Resource Key
        private static ComponentResourceKey _groupedHorizontallyTemplateKey;

        public static ResourceKey GroupedHorizontallyTemplateKey
        {
            get
            {
                if (_groupedHorizontallyTemplateKey == null)
                {
                    _groupedHorizontallyTemplateKey = new ComponentResourceKey(
                        typeof(GameButton),
                        "GroupedHorizontallyTemplateKey");
                }
                return _groupedHorizontallyTemplateKey;
            }
        }
        #endregion

        #region CheckboxTemplateKey Resource Key
        private static ComponentResourceKey _checkboxTemplateKey;

        public static ResourceKey CheckboxTemplateKey
        {
            get
            {
                if (_checkboxTemplateKey == null)
                {
                    _checkboxTemplateKey = new ComponentResourceKey(
                        typeof(GameButton),
                        "CheckboxTemplateKey");
                }
                return _checkboxTemplateKey;
            }
        }
        #endregion

        #endregion

        #region Properties

        #region DisplayMode Property
        public static readonly DependencyProperty DisplayModeProperty = DependencyProperty.Register(
            "DisplayMode",
            typeof(GameButtonDisplayMode),
            typeof(GameButton),
            new FrameworkPropertyMetadata(
                GameButtonDisplayMode.Normal,
                FrameworkPropertyMetadataOptions.None));

        public GameButtonDisplayMode DisplayMode
        {
            get { return (GameButtonDisplayMode)GetValue(DisplayModeProperty); }
            set { SetValue(DisplayModeProperty, value); }
        }
        #endregion

        #endregion

        #region Constructors and Finalizers
        static GameButton()
        {
            DefaultStyleKeyProperty.OverrideMetadata(
                typeof(GameButton),
                new FrameworkPropertyMetadata(typeof(GameButton)));
        }

        public GameButton() {}

        public GameButton(ICommand command)
            : this()
        {
            this.Command = command;
        }
        #endregion

        #region Method Overrides
        protected override object CoerceCommandParameter(DependencyObject obj, object value)
        {
            if ((value != null) || (this.Command == null))
                return value;

            if (_defaultCommandParameter == null)
                _defaultCommandParameter = new CheckableCommandParameter();

            return _defaultCommandParameter;
        }
        #endregion
    }
}